package priv.stones.jdbc;

import java.sql.*;

/**
 * @Author: Stones
 * @Description:
 * @Date: 2017/9/26 15:33
 */
public class Jdbc1 {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
//        Class.forName("com.mysql.jdbc.Driver");
        Connection cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/spider1?serverTimezone=UTC&characterEncoding=utf8&useSSL=true&useUnicode=true",
                "root", "Hujinyang1");
        System.out.println(cn);

        Statement statement = cn.createStatement();
        String name = "hu' or 'lei1";
        int age = 2220;
//        int result_add1 = statement.executeUpdate("insert into test (name,age) values('"+name+"',"+age+")");
//        System.out.println(result_add1);

        PreparedStatement preparedStatement = cn.prepareStatement("insert into test(name,age) VALUES (?,?)");
        preparedStatement.setString(1, name);
        preparedStatement.setInt(2, age);

        int result_add3 = preparedStatement.executeUpdate();
        System.out.println(result_add3);

//        boolean result_add2 = statement.execute("insert into test (name,age) values('hulei2',220)");
//        System.out.println(result_add2);


        cn.close();
    }

}
